const bt = require('./bt');

//二叉树的后序遍历(递归)
const postorder_1 = (root) => {
    if (!root) {return;}
    postorder_1(root.left);
    postorder_1(root.right);
    console.log(root.val);
};

postorder_1(bt);

//二叉树的后序遍历(非递归)
const postorder_2 = (root) => {
    if (!root){return;}
    const outputStack = [];
    const stack = [root];
    while (stack.length){
        const n = stack.pop();
        outputStack.push(n);
        if (n.left) stack.push(n.left);
        if (n.right) stack.push(n.right);
    }
    while (outputStack.length){
        const n = outputStack.pop();
        console.log(n.val);
    }
}